$(function(){
  $(".login").on("click",function(){
    var username = $("[name = username]").val();
    var password = $("[name = password]").val();
    if(!username ){
      mui.toast('请输入用户名') ;
      return;
    }
    if(!password ){
      mui.toast('请输入密码') ;
      return;
    }
    $.ajax({
      url:'/user/login',
      type:'post',
      data:{
        username:username,
        password:password
      },
      success:function(info){
        console.log(info);
        if(info.error === 403){
           mui.toast('用户名不存在或密码错误') ;
        }
        if(info.success){
          // 判断有没有backUrl
          var backUrl = getSearch().backUrl;
          if(backUrl){
            backUrl = backUrl.split("?")[0];
            console.log(backUrl);
            location.href = backUrl;
          }else{
            location.href = "user.html";
          }
          
        }
      }
    })

  })
})